<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search'>
        <div novalidate class="form-inline auto" partial>
          <div class="form-group">
            <!-- 用户名: -->
            <input type="text" class="form-control" v-model="model.f_user_name" v-on:keyup.enter="search"
            placeholder="用户名" condition="f_user_name like '{}%'">
          </div>
          <div class="form-group">
            <!-- 用户电话: -->
            <input type="text" class="form-control" v-model="model.f_user_phone" v-on:keyup.enter="search"
            placeholder="用户电话" condition="f_user_phone like '{}%'">
          </div>
          <div class="form-group">
            <!-- 小区地址: -->
            <input type="text" class="form-control" v-model="model.f_residential_area" v-on:keyup.enter="search"
            placeholder="小区地址" condition="f_residential_area like '%{}%'">
          </div>
          <div class="form-group">
            <!-- 建档月份 -->
            <datepicker id="startdate"
              placeholder="建档月份"
              :value.sync="$parent.$parent.model.f_archive_date"
              :disabled-days-of-Week="[]"
              :format="'yyyy-MM'">
            </datepicker>
          </div>
          <div class="form-group">
            <!-- <label for="f_subcompany">分公司：</label> -->
            <v-select id="f_subcompany"
            placeholder='分公司'
            :value.sync="$parent.$parent.model.f_subcompany"
            :options='$parent.$parent.subcompanyType'
            close-on-select clear-button></v-select>
          </div>
          <div class="form-group">
            <!-- <label for="f_user_state">档案状态：</label> -->
            <v-select id="f_user_state"
            placeholder='档案状态'
            :value.sync="$parent.$parent.model.f_user_state"
            :options='$parent.$parent.user_statesType'
            close-on-select clear-button></v-select>
          </div>
          <div class="form-group">
            <!-- <label for="f_user_state">安检员:</label> -->
            <input type="text" class="form-control" v-model="model.f_checker" v-on:keyup.enter="search"
            placeholder="安检员" condition="f_checker = '{}'">
          </div>
          <!-- <button class="btn btn-default" @click="search()">查询</button> -->
          <div class="form-group">
            <button class="btn btn-success width-80" @click="search()">查询</button>
          </div>

        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>用户编号</th>
            <th>用户姓名</th>
            <th>安检负责人</th>
            <th>所属子公司</th>
            <th>建档日期</th>
            <th>用户类型</th>
            <th>详细地址</th>
            <th>是否录入</th>
            <th>状态</th>
            <th>修改</th>
            <th>设置状态</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{row.f_user_id}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_checker }}</td>
          <td>{{row.f_subcompany}}</td>
          <td>{{row.f_archive_date}}</td>
          <td>{{row.f_user_type}}</td>
          <td>{{row.f_address}}</td>
          <td>{{row.f_sign=='1'?'是':'否'}}</td>
          <td>{{row.f_state}}</td>
          <td>
            <button class="btn btn-default"  @click='$parent.$parent.$parent.change(row)'>修改</button>
          </td>
          <td>
            <button class="btn btn-default"  @click="$parent.$parent.$parent.writeoff(row, '正常')">正常</button>
            <button class="btn btn-default"  @click="$parent.$parent.$parent.writeoff(row, '注销')">注销</button>
            <button class="btn btn-default"  @click="$parent.$parent.$parent.writeoff(row, '点火')">点火</button>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'
import co from 'co'
import AppData from '../../stores/AppData'

let writeOff = function * (self, row, state) {
  yield self.$post('rs/logic/档案状态修改', { data: {id: row.id, f_state: state} }, {resolveMsg: '修改状态成功！', rejectMsg: '修改状态失败！'}).then((response) => {
    row.f_state = state
  })
}

export default {
  title: '档案修改',
  props: ['f'],
  data () {
    let model = new PagedList('rs/sql/用户档案查询', 20, {items: '"*"', tablename: '"t_userfiles"', groupitem: '""', orderitem: '"f_user_id"',
    f_subcompany: 'this.f_subcompany[0]', f_archive_date: 'this.f_archive_date', f_state: 'this.f_user_state[0]'})
    model.f_subcompany = [Vue.f_subcompany]
    model.f_archive_date = ''
    model.f_user_state = ['']
    return {
      model: model
      // f_divisions: Vue.f_subcompany != '' ? [{label: Vue.f_subcompany, value: Vue.f_subcompany}]: this.$getParams('安检系统用子公司', [{label:'请选择分公司',value:''}]),
      // f_user_states: this.$getParams('用户档案状态', [{label:'请选择用户档案状态',value:''}])
    }
  },
  methods: {
    change (row) {
      this.$goto('userfile-change', {model: row, f: this.f})
    },
    writeoff (row, state) {
      let gen = writeOff(this, row, state)
      return co(gen)
    }
  },
  computed: {
    user_statesType () {
      return [{label: '全部', value: ''}, ...AppData.getParam('档案状态')]
    },
    subcompanyType () {
      return [{label: '全部', value: ''}, ...AppData.getParam('分公司')]
    }
  }
}
</script>
